package com.capri.activity;

import android.os.Bundle;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.capri.R;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AllOrdersActivity extends FragmentActivity {
    @BindView(R.id.tl_tabs)
    TabLayout tlTabs;
    @BindView(R.id.vp_content)
    ViewPager vpContent;

    List<Fragment> fragments = new ArrayList<>();
    List<String> titles = new ArrayList<>();

    public void setupView() {
        ButterKnife.bind(this);
        fragments.add(OrderListFragment.newInstance("all"));//全部
        fragments.add(OrderListFragment.newInstance("waitConfirm"));//待接单
        fragments.add(OrderListFragment.newInstance("waitStartOff"));//待出诊
        fragments.add(OrderListFragment.newInstance("startOff"));//已出诊
        fragments.add(OrderListFragment.newInstance("arrived"));//已到达
        fragments.add(OrderListFragment.newInstance("startService"));//服务中
        fragments.add(OrderListFragment.newInstance("serviceFinish"));//已结束
        titles.add("全部");
        titles.add("待接单");
        titles.add("待出诊");
        titles.add("已出诊");
        titles.add("已到达");
        titles.add("服务中");
        titles.add("已结束");
        vpContent.setAdapter(new FragmentPagerAdapter( getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                super.destroyItem(container, position, object);
            }


            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return titles.get(position);
            }
        });
        tlTabs.setupWithViewPager(vpContent);
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all_orders);
        ButterKnife.bind(this);
        setupView();
    }
}
